<?php 

	include("config.php");
    include(INCLUDEDIR."core.php");
	include("acceso.php");
	
	$tpl = new Plantilla();
	$tpl->setPlantilla("tpl.clientes.html");
	$tpl->prepare();
	

	$texto = isset($_GET['texto'])?sanitizar($_GET['texto']):"";

	$tpl->newBlock("FORMULARIOCLIENTE");
	$tpl->assign("texto",$texto);
	
	if($_POST) {
		$arr = array();
		foreach($_POST as $k => $v) {
			$arr[] = $k."=".urlencode($v);
		}
		header("location: clientes.php?".implode($arr,"&"));
		exit();
	}
	
	
	
	$query = "SELECT * FROM clientes INNER JOIN institutos ON clientes.id_instituto = institutos.id_instituto ";
	
	$filtros = array();
	if(strlen($texto)>1) {
		$filtros[] = db::SearchText($texto,array ("clientes","institutos") );
	}
	
	if(count($filtros)>0) {
		$query = $query . " WHERE (".implode(" AND ",$filtros).")";	
	}
	
	$result = mysql_query($query);
	if($result && mysql_num_rows($result)>0) {
		$tpl->newBlock("LISTACLIENTES");	
		while($fila = mysql_fetch_assoc($result)) {
			$tpl->newBlock("FILACLIENTE");
			foreach($fila as $key => $value) {
				$tpl->assign($key,$value);	
			}
		}
		
	} else {
		$tpl->newBlock("SINRESULTADOS");	
	}
	
	$tpl->Mostrar();
?>